



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class TicketImagesDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public TicketImagesDB()
        {
        }

        public TicketImagesDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<TicketImages> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<TicketImages> lstRet = new List<TicketImages>();

            string strQuery = " select " + strTop  + " * from dbo.[TicketImages]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    TicketImages obj = new TicketImages();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["TicketImage"] != DBNull.Value)
                    {
                        obj.TicketImage = (System.String)dr["TicketImage"];
                    }
                    else
                    {
                        obj.TicketImage = "";
                    } 
 if (dr["TicketID"] != DBNull.Value)
                    {
                        obj.TicketID = (System.Int64)dr["TicketID"];
                    }
                    else
                    {
                        obj.TicketID = -1;
                    } 
 if (dr["MessageID"] != DBNull.Value)
                    {
                        obj.MessageID = (System.Int64)dr["MessageID"];
                    }
                    else
                    {
                        obj.MessageID = -1;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<TicketImages> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<TicketImages> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , TicketImages obj)
        {
            
            

                    DbParameter prmTicketImage = con.createParameter();
                    prmTicketImage.ParameterName = "@TicketImage";
                    prmTicketImage.DbType =DbType.String;
                    if (obj.TicketImage == null)
                    {
                        prmTicketImage.Value = DBNull.Value;
                    }
                    else
                    {
                        prmTicketImage.Value = obj.TicketImage;
                    }
                

                    


                    DbParameter prmTicketID = con.createParameter();
                    prmTicketID.ParameterName = "@TicketID";
                    prmTicketID.DbType =DbType.Int64;
                    if (obj.TicketID == null)
                    {
                        prmTicketID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmTicketID.Value = obj.TicketID;
                    }
                

                    


                    DbParameter prmMessageID = con.createParameter();
                    prmMessageID.ParameterName = "@MessageID";
                    prmMessageID.DbType =DbType.Int64;
                    if (obj.MessageID == null)
                    {
                        prmMessageID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmMessageID.Value = obj.MessageID;
                    }
                

                    


           



            string strQuery = " insert into dbo.[TicketImages] ([TicketImage],[TicketID],[MessageID]) VALUES (@TicketImage,@TicketID,@MessageID) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmTicketImage,prmTicketID,prmMessageID);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(TicketImages obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, TicketImages obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmTicketImage = con.createParameter();
                    prmTicketImage.ParameterName = "@TicketImage";
                    prmTicketImage.DbType =DbType.String;
                    if (obj.TicketImage == null)
                    {
                        prmTicketImage.Value = DBNull.Value;
                    }
                    else
                    {
                        prmTicketImage.Value = obj.TicketImage;
                    }
                

                    


                    DbParameter prmTicketID = con.createParameter();
                    prmTicketID.ParameterName = "@TicketID";
                    prmTicketID.DbType =DbType.Int64;
                    if (obj.TicketID == null)
                    {
                        prmTicketID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmTicketID.Value = obj.TicketID;
                    }
                

                    


                    DbParameter prmMessageID = con.createParameter();
                    prmMessageID.ParameterName = "@MessageID";
                    prmMessageID.DbType =DbType.Int64;
                    if (obj.MessageID == null)
                    {
                        prmMessageID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmMessageID.Value = obj.MessageID;
                    }
                

                    


           



            string strQuery = " update dbo.[TicketImages] set [TicketImage]=@TicketImage,[TicketID]=@TicketID,[MessageID]=@MessageID where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmTicketImage,prmTicketID,prmMessageID);

            

        }


        public void Update(TicketImages obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, TicketImages obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[TicketImages]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( TicketImages obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<TicketImages> getTicketImagesByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<TicketImages> lstRet = new List<TicketImages>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<TicketImages> getTicketImagesByID(System.Int64 ID)
                    {
                        List<TicketImages> lstRet = new List<TicketImages>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketImagesByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<TicketImages> getTicketImagesByTicketImage(ClassDataHandler con,System.String TicketImage)
                    {
                        List<TicketImages> lstRet = new List<TicketImages>();


                        DbParameter prmTicketImage = con.createParameter();
                        prmTicketImage.ParameterName = "@TicketImage";
                        prmTicketImage.DbType = DbType.String;
                        if (TicketImage == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmTicketImage.Value = TicketImage;
                        }


                        lstRet = Select(con, "" , " where [TicketImage]=@TicketImage ", prmTicketImage);



                        return lstRet;

                    }


                    public List<TicketImages> getTicketImagesByTicketImage(System.String TicketImage)
                    {
                        List<TicketImages> lstRet = new List<TicketImages>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketImagesByTicketImage(con, TicketImage);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<TicketImages> getTicketImagesByTicketID(ClassDataHandler con,System.Int64 TicketID)
                    {
                        List<TicketImages> lstRet = new List<TicketImages>();


                        DbParameter prmTicketID = con.createParameter();
                        prmTicketID.ParameterName = "@TicketID";
                        prmTicketID.DbType = DbType.Int64;
                        if (TicketID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmTicketID.Value = TicketID;
                        }


                        lstRet = Select(con, "" , " where [TicketID]=@TicketID ", prmTicketID);



                        return lstRet;

                    }


                    public List<TicketImages> getTicketImagesByTicketID(System.Int64 TicketID)
                    {
                        List<TicketImages> lstRet = new List<TicketImages>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketImagesByTicketID(con, TicketID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<TicketImages> getTicketImagesByMessageID(ClassDataHandler con,System.Int64 MessageID)
                    {
                        List<TicketImages> lstRet = new List<TicketImages>();


                        DbParameter prmMessageID = con.createParameter();
                        prmMessageID.ParameterName = "@MessageID";
                        prmMessageID.DbType = DbType.Int64;
                        if (MessageID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmMessageID.Value = MessageID;
                        }


                        lstRet = Select(con, "" , " where [MessageID]=@MessageID ", prmMessageID);



                        return lstRet;

                    }


                    public List<TicketImages> getTicketImagesByMessageID(System.Int64 MessageID)
                    {
                        List<TicketImages> lstRet = new List<TicketImages>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getTicketImagesByMessageID(con, MessageID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<TicketImages> Search(ClassDataHandler con, TicketImages obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.TicketImage != "")
                    {
                        DbParameter prmTicketImage = con.createParameter();
                        prmTicketImage.ParameterName = "@TicketImage";
                        prmTicketImage.DbType =DbType.String;
                        if (obj.TicketImage == null)
                        {
                            prmTicketImage.Value = DBNull.Value;
                        }
                        else
                        {
                            prmTicketImage.Value = obj.TicketImage;
                        }
                        strWhere += " [TicketImage]=@TicketImage AND ";
                        lstParameters.Add(prmTicketImage);
                     }



                    

                    if (obj.TicketID != -1)
                    {
                        DbParameter prmTicketID = con.createParameter();
                        prmTicketID.ParameterName = "@TicketID";
                        prmTicketID.DbType =DbType.Int64;
                        if (obj.TicketID == null)
                        {
                            prmTicketID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmTicketID.Value = obj.TicketID;
                        }
                        strWhere += " [TicketID]=@TicketID AND ";
                        lstParameters.Add(prmTicketID);
                     }



                    

                    if (obj.MessageID != -1)
                    {
                        DbParameter prmMessageID = con.createParameter();
                        prmMessageID.ParameterName = "@MessageID";
                        prmMessageID.DbType =DbType.Int64;
                        if (obj.MessageID == null)
                        {
                            prmMessageID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmMessageID.Value = obj.MessageID;
                        }
                        strWhere += " [MessageID]=@MessageID AND ";
                        lstParameters.Add(prmMessageID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<TicketImages> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<TicketImages> Search(TicketImages obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<TicketImages> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<TicketImages> SearchOrLike(ClassDataHandler con, TicketImages obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.TicketImage != "")
                    {
                        DbParameter prmTicketImage = con.createParameter();
                        prmTicketImage.ParameterName = "@TicketImage";
                        prmTicketImage.DbType =DbType.String;
                        if (obj.TicketImage == null)
                        {
                            prmTicketImage.Value = DBNull.Value;
                        }
                        else
                        {
                            prmTicketImage.Value = obj.TicketImage;
                        }
                        strWhere += " [TicketImage] LIKE @TicketImage OR ";
                        lstParameters.Add(prmTicketImage);
                     }



                    

                    if (obj.TicketID != -1)
                    {
                        DbParameter prmTicketID = con.createParameter();
                        prmTicketID.ParameterName = "@TicketID";
                        prmTicketID.DbType =DbType.Int64;
                        if (obj.TicketID == null)
                        {
                            prmTicketID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmTicketID.Value = obj.TicketID;
                        }
                        strWhere += " [TicketID]=@TicketID OR ";
                        lstParameters.Add(prmTicketID);
                     }



                    

                    if (obj.MessageID != -1)
                    {
                        DbParameter prmMessageID = con.createParameter();
                        prmMessageID.ParameterName = "@MessageID";
                        prmMessageID.DbType =DbType.Int64;
                        if (obj.MessageID == null)
                        {
                            prmMessageID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmMessageID.Value = obj.MessageID;
                        }
                        strWhere += " [MessageID]=@MessageID OR ";
                        lstParameters.Add(prmMessageID);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<TicketImages> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<TicketImages> SearchOrLike(TicketImages obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<TicketImages> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            